<?php
require_once("../bd/ConexionBD.class.php");
require_once("../bd/AccesoBD.class.php");

class Cliente{
	private $cn;
	
	function __construct(){
		$cadena = ConexionBD::CadenaCN();
		$this->cn = AccesoBD::ConexionBD($cadena);
	}
	
	public function Login($email, $pass){
		try {
			$sql = "SELECT * FROM cliente WHERE email_cliente='$email' and contrasena_cliente=sha1('$pass')";
			$cliente = AccesoBD::Consultar($this->cn, $sql);
			return $cliente[0];
		}catch(Exception $e){
			throw $e;
		}
	}
	
	public function Registrar($nom,$direc,$email,$pass){
		try { 
			$sql = "INSERT INTO cliente(nombre_cliente,direccion_cliente,email_cliente,contrasena_cliente) VALUES('$nom','$direc','$email',sha1('$pass'))";
			$id_cliente = AccesoBD::Insertar($this->cn, $sql);
			return $id_cliente;
		} catch (Exception $e) {
		throw $e;
		}
	}
	
	public function BuscarID($id_cliente){
		try {
			$sql = "SELECT * FROM cliente WHERE id_cliente = $id_cliente";
			$cliente = AccesoBD::Consultar($this->cn, $sql);
			return $cliente[0];
		}catch(Exception $e){
			throw $e;
		}
	}
	
	
}